<?php
final class XAOPContext{
	private static $instance = null;
	private $pointcuts = array();
	private $beforeAdvices = array();
	private $afterReturningAdvices = array();
	private $afterThrowingAdvices = array();
	private $afterAdvices = array();
	private $aroundAdvices = array();
	
	private function __construct() {
	
	}
	
	/** 
	 * @return XAOPContext
	 */	
	static function singleton() {
		if (!self::$instance) {
			self::$instance = new self;
		}
		return self::$instance;
	}
	
	/** 
	 * @return XAOPContext
	 */		
	public function addPointcut(XPointcut $pointcut){
		$this->pointcuts[$pointcut->getName()] = $pointcut;
		return $this;
	}
	
	public function pointcuts(){
		return $this->pointcuts;
	}
	
	public function pointcut($name){
		if(isset($this->pointcuts[$name])){
			return $this->pointcuts[$name];
		}
		return null;
	}	
	
	/** 
	 * @return XAOPContext
	 */		
	public function addBeforeAdvice($beforeAdvice){
		$this->beforeAdvices[] = $beforeAdvice;
		return $this;
	}
	
	public function beforeAdvices(){
		return $this->beforeAdvices;
	}
	
	/** 
	 * @return XAOPContext
	 */		
	public function addAfterReturningAdvice($afterReturningAdvice){
		$this->afterReturningAdvices[] = $afterReturningAdvice;
		return $this;
	}	
	
	public function afterReturningAdvices(){
		return $this->afterReturningAdvices;
	}
	
	/** 
	 * @return XAOPContext
	 */		
	public function addAfterThrowingAdvice($afterThrowingAdvice){
		$this->afterThrowingAdvices[] = $afterThrowingAdvice;
		return $this;
	}
	
	public function afterThrowingAdvices(){
		return $this->afterThrowingAdvices;
	}	
	
	/** 
	 * @return XAOPContext
	 */		
	public function addAfterAdvice($afterAdvice){
		$this->afterAdvices[] = $afterAdvice;
		return $this;
	}
	
	public function afterAdvices(){
		return $this->afterAdvices;
	}	

	/** 
	 * @return XAOPContext
	 */		
	public function addAroundAdvice($aroundAdvice){
		$this->aroundAdvices[] = $aroundAdvice;
		return $this;
	}
	
	public function aroundAdvices(){
		return $this->aroundAdvices;
	}		
}
?>